<?php
/**
 * group_info表model
 * 
 * @author sz 2016-9-14 11:32:53
 * @version 1.0
 */
namespace Home\Model;
use Think\Model;

class GroupInfoModel extends Model
{

    /**
     * model对应表和数据库信息
     *
     * @author sz 2016-9-14 11:33:02
     * @version 1.0
     */
    function __construct ()
    {
        parent::__construct('group_info', null, 'HAICHUANG');
    }

    /**
     * getGroupInfo
     *
     * @param            
     *
     * @return 获取商铺信息
     * @author sz 2016-9-14 11:33:06
     * @version 1.0
     */
    public function getGroupInfo ()
    {
        $sql = "SELECT id,name,introduce,update_time FROM group_info ORDER BY update_time DESC";
        
        return $this->query($sql);
    }
    
    /**
     * getGroupByName
     *
     * @param string $group_name
     *            指定的分组名称
     * @return 根据分组名称获取分组信息
     * @author sz 2016-9-14 11:33:06
     * @version 1.0
     */
    public function getGroupByName ($group_name)
    {    
        return $this->field('id,name')->where("name='$group_name'")->select();
    }
    
    /**
     * getGroupById
     *
     * @param string $group_id
     *            指定的分组id
     * @return 根据分组名称获取分组信息
     * @author sz 2016-9-20 10:43:42
     * @version 1.0
     */
    public function getGroupById ($group_id)
    {
        return $this->field('id,name,introduce,auth_ids')->where("id=$group_id")->select();
    }

    /**
     * 插入一条操作数据
     *
     * @param string $group_name
     *            指定的分组名称
     * @param string $group_introduce
     *            分组介绍
     * @return 插入成功，返回插入数据ID；插入失败或异常返回false
     * @author sz 2016-9-20 10:13:448
     * @version 1.0
     */
    public function addGroup($group_name, $group_introduce)
    {
        $dataArray = array();
        $dataArray['name'] = $group_name;
        $dataArray['introduce'] = $group_introduce;
        $dataArray['create_time'] = array(
                'exp',
                'now()'
        );
        return $this->add($dataArray);
    }   
    
    /**
     * 修改一条操作数据
     *
     *@param string $group_id
     *            指定的分组id
     * @param string $group_name
     *            指定的分组名称
     * @param string $group_introduce
     *            分组介绍
     * @return 插入成功，返回插入数据ID；插入失败或异常返回false
     * @author sz 2016-9-20 11:08:10
     * @version 1.0
     */
    public function modifyGroup($group_id, $group_name, $group_introduce)
    {
        $dataArray = array();
        $dataArray['name'] = $group_name;
        $dataArray['introduce'] = $group_introduce;
        return $this->where("id=$group_id")->save($dataArray);
    }
    
    /**
     * 修改一条操作数据
     *
     *@param string $group_id
     *            指定的分组id
     * @param string $group_name
     *            指定的分组名称
     * @param string $group_introduce
     *            分组介绍
     * @return 插入成功，返回插入数据ID；插入失败或异常返回false
     * @author sz 2016-9-20 11:08:10
     * @version 1.0
     */
    public function setAuth($group_id, $auth_ids)
    {
        $dataArray = array();
        $dataArray['auth_ids'] = $auth_ids;
        return $this->where("id=$group_id")->save($dataArray);
    }
    
    /**
     * del
     *
     * @param
     *
     *
     * @return 删除成功true，失败返回false
     * @author sz 2016-8-31 13:33:09
     * @version 1.0
     */
    public function del ($id)
    {
        return $this->where("id=$id")->delete();
    }
}
?>